import { createRouter, createWebHashHistory, RouteLocationNormalized } from 'vue-router';
import routes from './routes';
const { VITE_BASE_URL } = import.meta.env;
const router = createRouter({
  history: createWebHashHistory(VITE_BASE_URL),
  routes
});

const setTitle = (to: RouteLocationNormalized) => {
  // 设置页面标题
  document.title = (to.meta && (to.meta.title as string)) || '校园舆情预警大屏';
};

// 路由拦截
router.beforeEach(to => {
  setTitle(to);
});

export default router;
